<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>摄氏度与华氏转换</title>
    <script>
        function convert(degree) {
            if (degree == "C") {
                F = document.getElementById("c").value * 9 / 5 + 32;
                document.getElementById("f").value = Math.round(F);
            }
            else {
                C = (document.getElementById("f").value - 32) * 5 / 9;
                document.getElementById("c").value = Math.round(C);
            }
        }
    </script>
</head>

<body>
    <p><b>在下面输入框中插入一个数值：</b></p>
    <form>
        <input id="c" name="c" onkeyup="convert('C')"> 摄氏度<br>
        等于<br>
        <input id="f" name="f" onkeyup="convert('F')"> 华氏度
    </form>
    <p>注意使用<b>Math.round()</b> 方法返回的结果是一个整数。</p>
</body>

</html>